<?php
class HuashuAction extends CommonAction
{
    public function index()
    {
        $username = I("session.userid");
        $account = D('Huashu'); // 实例化模型类
        $count = $account->count();
        //分页显示文章列表，每页20篇文章
        import('ORG.Util.Page');
        $page = new Page($count, 20); //后台管理页面默认一页显示8条文章记录
        $page->setConfig('prev', "上一页"); //上一页
        $page->setConfig('next', '下一页'); //下一页
        $page->setConfig('first', '首页'); //第一页
        $page->setConfig('last', '尾页'); //最后一页
        $page->setConfig('theme', ' %first% %upPage%  %linkPage%  %downPage% %end%');
        //设置分页回调方法
        $show = $page->show();
        //$list=$account->join('ys_remarks on ys_custom.id=ys_remarks.customid')->GROUP('ys_custom.id')->order('ys_remarks.id desc')->limit($page->firstRow.','.$page->listRows)->select();// 查询数据
        $firstpage = $page->firstRow;
        $lastpage = $page->listRows;
        $list = $account->query("select * from ys_huashu where adduser='$username' limit $firstpage,$lastpage");
        //$account->getlastsql();
        //$account->getlastsql();
        $this->assign('accounts_list', $list); // 数据列表变量赋值
        $this->assign('page_method', $show); //分页列表变量赋值
        $this->display(); // 输出模板
    }

    public function newsave()
    {
        $myinfo = I("session.my_info");
        $username = $myinfo["id"];
        $newuser = M('huashu'); // 实例化模型类
        if ($newuser->create())
        {
            $newuser->adduser = $username;
            $newuser->mark = $_POST['mark'];
            $vo = $newuser->add();
            $this->show('<script type="text/javascript" src="__PUBLIC__/libs/js/jquery.js"></script><script type="text/javascript">$(function(){top.Dialog.alert("成功提交",function(){window.parent.frmright.location.reload();top.Dialog.close()})})</script>', 'utf-8');
        } else
        {
            echo '信息添加失败，请检查网络！';
        }
    }

    public function edit()
    {
        $id = $_GET['id'];
        $useredit = M('Huashu');
        $data = $useredit->where("id=$id")->find();
        $this->assign('id', $id);
        $this->assign('mark', $data['mark']);
        $this->display();
    }

    public function editsave()
    {
        $username = I("session.userid");
        $custom = M('Huashu');
        $data = array('adduser' => $username, 'mark' => $_POST['mark']);
        $id = $_GET['id'];
        $custom->where("id=$id")->setField($data); // 根据条件保存修改的数据
        $url=U('Huashu/index');
        $info=<<<EOT
<script type="text/javascript" src="__PUBLIC__/libs/js/jquery.js"></script>
<script type="text/javascript">
$(function(){
    top.Dialog.alert("修改成功！",
    function(){
        window.parent.frmright.location.href="$url";
        top.Dialog.close()
    })
})
</script>
EOT;

        $this->show($info, 'utf-8');
    }
}

?>